package com.vecspace.web.freemarker;

import java.util.HashMap;
import java.util.Map;

/**缓存freemarker模版
 * StringTemplateLoader会使用此缓存中的模版内容
 * @author: wanghua
 */
public class StringTemplateCache {
	private static StringTemplateCache _instance = new StringTemplateCache();
	public static StringTemplateCache instance(){
		return _instance;
	}
	
	private Map<String, String> templates = new HashMap<>();
	private StringTemplateCache(){
		
	}
	
	/**synchronized 
	 * @param name
	 * @param template 
	 * @author: wanghua
	 */
	public synchronized void addTemplate(String name, String template){
		templates.put(name, template);
	}
	
	public String getTemplate(String name){
		String template = templates.get(name);
		return template;
	}
	
	public void clear(){
		templates.clear();
	}
	
	private static boolean useCache = true;
	public boolean isUseCache() {
		return useCache;
	}

	public void setUseCache(boolean useCache) {
		StringTemplateCache.useCache = useCache;
	}	
}
